﻿@using WebApp.Extensions
@model Dto.ApiResponses.AttachmentResponses.AttachmentSearchResponse

@{
    ViewBag.CurrentPage = WebApp.Common.PageSetting.SearchPageSetting;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{ var sectionId = (Request.IsAjaxRequest() ? "Ajax" : "View") + "_Search"; }

@section Scripts{
    <script type="text/javascript">
        require(['Search/Index', 'Util'], function (api, util) {
            var model = util.toJS(@(Html.ToJson(Model)));
            $(function () { api.exec('@sectionId', model); });
        });
    </script>
}


<div class="container" data-bind="stopbinding: true">
    <section id="@sectionId">
        <div class="row spacer">
            <fieldset>
                <legend>Search Result</legend>
                <div class="col-md-8">
                </div>
                <div class="col-md-3">
                    <input type="text" class="form-control col-md-2 pull-right" data-bind="value:value, valueUpdate: 'afterkeydown', executeOnEnter: search" placeholder="Search by Name or Tags" />
                </div>
                <div class="col-md-1">
                    <button data-bind="click: search" class="btn btn-default btn-lg btn-primary" type="button">Go!</button>
                </div>
            </fieldset>
            <div class="row spacer" data-bind="visible: attachments().length > 0">
                <div style="overflow: auto">
                    <table class="table table-bordered table-hover table-condensed">
                        <thead>
                            <tr>
                                <th>Attachment Name</th>
                                <th>Tags</th>
                                <th>Parent Name</th>
                                <th>Parent Type</th>
                                <th>Created By</th>
                                <th>Created On</th>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- ko foreach: attachments -->
                            <tr>
                                <td class="col-xs-2"><a href="#" data-bind="text: name,attr:{'href':'/attachment/Index?Id=' + id()}"></a></td>
                                <td class="col-xs-3"><span data-bind="text: tags"></span></td>
                                <td class="col-xs-2"><a data-bind="text: referenceName,attr:{'href' : parentUrl()}"></a></td>
                                <td class="col-xs-2"><span data-bind="text: entityTypeName"></span></td>
                                <td class="col-xs-2"><span data-bind="text: createdByName"></span></td>
                                <td class="col-xs-2"><span data-bind="text: createdOn"></span></td>
                            </tr>
                            <!-- /ko -->
                        </tbody>
                    </table>
                </div>
            </div>
            <div data-bind="visible: attachments().length == 0" style="margin-left:0">
                <span>No Records found.</span>
            </div>
        </div>
    </section>
</div>


